// 扩展图片索引至8张
function createPhotoElements() {
  const album = document.querySelector('.photo-album');
  for (let i = 1; i <= 8; i++) {
    const photo = document.createElement('div');
    photo.className = 'photo';
    photo.innerHTML = `<img src="assets/images/photo${i}.png" alt="照片${i}">`;
    album.appendChild(photo);
  }
}

// 事件委托优化按钮点击
let isRotating = true;
let rotateInterval;

document.addEventListener('click', (e) => {
  const target = e.target;
  if (target.classList.contains('prev')) handlePrev();
  else if (target.classList.contains('next')) handleNext();
  else if (target.classList.contains('play-pause')) {
    isRotating = !isRotating;
    target.querySelector('i').classList.toggle('fa-pause');
    target.querySelector('i').classList.toggle('fa-play');
  }
});

// 新增移动端触摸支持
let startX = 0;
let endX = 0;
document.addEventListener('touchstart', (e) => {
  startX = e.touches[0].clientX;
});
document.addEventListener('touchend', (e) => {
  endX = e.changedTouches[0].clientX;
  if (endX - startX > 50) handlePrev();
  else if (startX - endX > 50) handleNext();
});